<script lang="ts" setup name="XtxConfirm">
import { onMounted, ref } from 'vue';
import XtxButton from '../button/index.vue'
defineProps<{
  title: string
  text: string
  cancelCallback: () => void
  confirmCallback: () => void
}>()

const isShow = ref(false)
// onMounted -> 该生命周期钩子函数中, 操作(获取)dom -> 不代表dom渲染完成
// 等待浏览器渲染/解析完成后, 才去修改状态, 所以才能看到动画效果 (合并渲染)
onMounted(() => {
  setTimeout(() => {
    isShow.value = true
  }, 30); // 宏任务 , 微任务
})
// 动画
// Transition 整体
// css        细节(精细)    
</script>
<template>
  <div class="xtx-confirm" :class="{ fade: isShow }">
    <div class="wrapper" :class="{ fade: isShow }">
      <div class="header">
        <h3>{{ title }}</h3>
        <a href="JavaScript:;" class="iconfont icon-close-new" @click="cancelCallback"></a>
      </div>
      <div class="body">
        <i class="iconfont icon-warning"></i>
        <span>{{ text }}</span>
      </div>
      <div class="footer">
        <XtxButton size="mini" @click="cancelCallback" type="gray">取消</XtxButton>
        <XtxButton size="mini" @click="confirmCallback" type="primary">确认</XtxButton>
      </div>
    </div>
  </div>
</template>

<style scoped lang="less">
.xtx-confirm {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  z-index: 8888;
  // 纯黑纯透明
  background: rgba(0, 0, 0, 0);
  &.fade {
  //  纯黑半透明  
    background: rgba(0, 0, 0, 0.5);
    transition: all .5s;
  }

  .wrapper {
    width: 400px;
    background: #fff;
    border-radius: 4px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -60%);
    opacity: 0;
    &.fade {
      transform: translate(-50%, -50%);
      opacity: 1;
      transition: all .5s;
    }


    .header,
    .footer {
      height: 50px;
      line-height: 50px;
      padding: 0 20px;
    }

    .body {
      padding: 20px 40px;
      font-size: 16px;

      .icon-warning {
        color: @priceColor;
        margin-right: 3px;
        font-size: 16px;
      }
    }

    .footer {
      text-align: right;

      .xtx-button {
        margin-left: 20px;
      }
    }

    .header {
      position: relative;

      h3 {
        font-weight: normal;
        font-size: 18px;
      }

      a {
        position: absolute;
        right: 15px;
        top: 15px;
        font-size: 20px;
        width: 20px;
        height: 20px;
        line-height: 20px;
        text-align: center;
        color: #999;

        &:hover {
          color: #666;
        }
      }
    }
  }
}
</style>
